cmake_minimum_required(VERSION 3.10)

set(CMAKE_BUILD_TYPE Debug)

project(SerialCommunication)

set(CMAKE_CXX_STANDARD 11)

# 查找 Boost 库
find_package(Boost REQUIRED COMPONENTS system)

# 查看 Eigen 库
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})

# 查找 libmodbus 库
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBMODBUS REQUIRED libmodbus)

# 包含 libmodbus 的头文件路径
include_directories(
    ${Boost_INCLUDE_DIRS}
    ${LIBMODBUS_INCLUDE_DIRS}
    ./include
)

set(SERVER_SOURCES
    src/server_test.cpp
    src/server.cpp
)
# 生成服务端测试程序
add_executable(server_test ${SERVER_SOURCES})
target_link_libraries(server_test ${Boost_LIBRARIES} pthread)

set(SOCKET_SOURCES
    src/serial_socket.cpp
    src/serial_kalman.cpp
    src/kalmanfilter.cpp
)
# 生成客户端程序，其中包含串口部分
add_executable(serial_socket ${SOCKET_SOURCES})
target_link_libraries(serial_socket ${Boost_LIBRARIES} pthread)

set(MODBUS_SOURCES
    src/serial_modbus.cpp
    src/serial_kalman.cpp
    src/kalmanfilter.cpp
)

# 生成modbus客户端程序，其中包含串口部分
add_executable(serial_modbus ${MODBUS_SOURCES})
target_link_libraries(serial_modbus ${Boost_LIBRARIES} ${LIBMODBUS_LIBRARIES} pthread)

set(MODBUS_KALMAN_SOURCES
    src/serial_modbus_kalman.cpp
    src/serial_kalman.cpp
    src/kalmanfilter.cpp
)

# 生成modbus客户端程序，其中包含串口部分和卡尔曼滤波估计
add_executable(serial_modbus_kalman ${MODBUS_KALMAN_SOURCES})
target_link_libraries(serial_modbus_kalman ${Boost_LIBRARIES} ${LIBMODBUS_LIBRARIES} pthread)

# 生成modbus服务端程序，其中包含串口部分
add_executable(server_modbus src/server_modbus.cpp)
target_link_libraries(server_modbus ${Boost_LIBRARIES} ${LIBMODBUS_LIBRARIES} pthread)

# 生成串口通信并保存文件的测试程序
add_executable(serial_csv src/serial_csv.cpp)
target_link_libraries(serial_csv ${Boost_LIBRARIES} pthread)

# 查找 Eigen
set(KALMAN_SOURCES
    src/kalman_test.cpp
    src/kalmanfilter.cpp
)
add_executable(kalman_test ${KALMAN_SOURCES})
